﻿using Biomedica.Graphics;
using Biomedica.Propability.StateMachine;
using KinectWindows.Nui.Nui.Postures;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NuiDicomPlayer.Nui.Nui
{
    public interface IInstage
    {
        void OnUserEnteredStage(StateContext Context);
        void OnUserExitedStage(StateContext Context);
        void OnUserInstage(StateContext context);
        void OnUserOutstage(StateContext Context);
    }
    public class UserInstageDectedtor : PostureDetectorBase
    {
        private float NearDist;
        private float FarDist;
        public UserInstageDectedtor(StateContext Context):base(10,Context)
        {
            NearDist = 0.5f;
            FarDist = 3.0f;
        }

        public void TrackPosture(Vector3 SkelPostion)
        {
            TrackPosture(new Vector3[] { SkelPostion });
        }
        public override void TrackPosture(Biomedica.Graphics.Vector3[] jointsPos)
        {
            if (checkUserInStage(jointsPos[0]))
            {
                RaisPostureDetected("UserInstage");
            }
            else
            {
                RaisPostureDetected("UserOutstage");
            }

            Reset();
        }
        private bool checkUserInStage(Vector3 pos)
        {
            if (!pos.HasValue) return false;

            if (pos.Z < NearDist) return false;
            if (pos.Z > FarDist) return false;
                

            return true;
        }
    }
}
